import { Cache } from "../../cache/Cache";
import { AutoFight } from "./AutoFight";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { SkillRules } from "../../rules/SkillRules";
import { ItemTypeManager } from "./ItemTypeManager";
type int = number;
//class AutoFightInfo
    
    export  class AutoFightInfo
    {
        constructor()
        {
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this.monsterArr = [];
            this.skillOther = [0, 0, 0];
            this.skillObj = {};
            this.skillShowObj = {};
            this.pickDrug = [];
            this.pickDrugIdx = [];
            this.pickOtherThings = [];
            this.pickOtherThingsIdx = [];
            
            this._map["attackMonster"] = "a";
            this._map["pickThing"] = "b";
            this._map["acceptTeam"] = "c";
            this._map["fSkill"] = "d";
            this._map["pSkill"] = "e";
            this._map["callPet"] = "f";
            this._map["backCity"] = "g";
            this._map["locRevive"] = "h";
            this._map["pickEquip"] = "i";
            this._map["careerEquip"] = "j";
            this._map["pickThings"] = "k";
            this._map["monsterArr"] = "l";
            this._map["skillArr"] = "m";
            this._map["skillOther"] = "n";
            this._map["petEatDrug"] = "o";
            this._map["skillIdx"] = "p";
            this._map["skillsArr"] = "q";
            this._map["pickDrugIdx"] = "r";
            this._map["pickOtherThingsIdx"] = "s";
            this._map["skillShowArr"] = "t";
            this._map["skillObj"] = "u";
            this._map["skillShowObj"] = "v";
            var loc1=Cache.instance.role.careerEnabled;
            this.skillObj[loc1.toString()] = this.getDefaultArrValue();
            this.skillShowObj[loc1.toString()] = this.getDefaultArrValue();
            return;
        }

        public setSkillArr(arg1, arg2: int): void
        {
            if (arg1 == null || arg2 < 0) 
            {
                return;
            }
            var loc1=Cache.instance.role.careerEnabled;
            if (this.skillObj == null) 
            {
                this.skillObj = {};
            }
            if (this.skillObj[loc1.toString()] == null) 
            {
                this.skillObj[loc1.toString()] = this.getDefaultArrValue();
            }
            this.skillObj[loc1.toString()][arg2] = arg1;
            return;
        }

        public serializeString(): string
        {
            var loc1=AutoFight.defaultAutoFight;
            var loc2=new Object();
            if (this.attackMonster != loc1.attackMonster) 
            {
                loc2[this._map["attackMonster"]] = this.attackMonster;
            }
            if (this.pickThing != loc1.attackMonster) 
            {
                loc2[this._map["pickThing"]] = this.pickThing;
            }
            if (this.acceptTeam != loc1.acceptTeam) 
            {
                loc2[this._map["acceptTeam"]] = this.acceptTeam;
            }
            if (this.fSkill != loc1.fSkill) 
            {
                loc2[this._map["fSkill"]] = this.fSkill;
            }
            if (this.pSkill != loc1.pSkill) 
            {
                loc2[this._map["pSkill"]] = this.pSkill;
            }
            if (this.callPet != loc1.callPet) 
            {
                loc2[this._map["callPet"]] = this.callPet;
            }
            if (this.backCity != loc1.backCity) 
            {
                loc2[this._map["backCity"]] = this.backCity;
            }
            if (this.locRevive != loc1.locRevive) 
            {
                loc2[this._map["locRevive"]] = this.locRevive;
            }
            if (this.petEatDrug != loc1.petEatDrug) 
            {
                loc2[this._map["petEatDrug"]] = this.petEatDrug;
            }
            loc2[this._map["pickEquip"]] = this.pickEquip;
            loc2[this._map["careerEquip"]] = this.careerEquip;
            loc2[this._map["pickThings"]] = this.pickThings;
            loc2[this._map["monsterArr"]] = this.monsterArr;
            loc2[this._map["skillOther"]] = this.skillOther;
            loc2[this._map["skillIdx"]] = this.skillIdx;
            loc2[this._map["pickDrugIdx"]] = this.pickDrugIdx;
            loc2[this._map["pickOtherThingsIdx"]] = this.pickOtherThingsIdx;
            loc2[this._map["skillObj"]] = this.skillObj;
            loc2[this._map["skillShowObj"]] = this.skillShowObj;
            return JSON.serialize(loc2);
        }

        public deserializeObj(arg1: string): Object
        {
            if (arg1 == "") 
            {
                return null;
            }
            var loc1=JSON.deserialize(arg1);
            if (!loc1) 
            {
                return null;
            }
            if (loc1.hasOwnProperty(this._map["attackMonster"])) 
            {
                this.attackMonster = loc1[this._map["attackMonster"]];
            }
            if (loc1.hasOwnProperty(this._map["pickThing"])) 
            {
                this.pickThing = loc1[this._map["pickThing"]];
            }
            if (loc1.hasOwnProperty(this._map["acceptTeam"])) 
            {
                this.acceptTeam = loc1[this._map["acceptTeam"]];
            }
            if (loc1.hasOwnProperty(this._map["fSkill"])) 
            {
                this.fSkill = loc1[this._map["fSkill"]];
            }
            if (loc1.hasOwnProperty(this._map["pSkill"])) 
            {
                this.pSkill = loc1[this._map["pSkill"]];
            }
            if (loc1.hasOwnProperty(this._map["callPet"])) 
            {
                this.callPet = loc1[this._map["callPet"]];
            }
            if (loc1.hasOwnProperty(this._map["backCity"])) 
            {
                this.backCity = loc1[this._map["backCity"]];
            }
            if (loc1.hasOwnProperty(this._map["locRevive"])) 
            {
                this.locRevive = loc1[this._map["locRevive"]];
            }
            if (loc1[this._map["pickEquip"]] >= -1) 
            {
                this.pickEquip = loc1[this._map["pickEquip"]];
            }
            if (loc1[this._map["careerEquip"]] >= 0) 
            {
                this.careerEquip = loc1[this._map["careerEquip"]];
            }
            if (loc1[this._map["pickThings"]] >= -1) 
            {
                this.pickThings = loc1[this._map["pickThings"]];
            }
            if (loc1[this._map["monsterArr"]] != null) 
            {
                this.monsterArr = loc1[this._map["monsterArr"]];
            }
            if (loc1[this._map["skillOther"]] != null) 
            {
                this.skillOther = loc1[this._map["skillOther"]];
            }
            if (loc1[this._map["petEatDrug"]] != null) 
            {
                this.petEatDrug = loc1[this._map["petEatDrug"]];
            }
            if (loc1[this._map["skillIdx"]] != null) 
            {
                this.skillIdx = loc1[this._map["skillIdx"]];
            }
            var loc2=this.reInitSkill(loc1);
            if (loc2 != null) 
            {
                this.skillObj[Cache.instance.role.careerEnabled.toString()] = loc2;
            }
            var loc3;
            if ((loc3 = this.reInitSkillShow(loc1, loc2)) == null && !(loc2 == null)) 
            {
                this.copyArray(loc2, loc3);
            }
            if (loc3 != null) 
            {
                this.skillShowObj[Cache.instance.role.careerEnabled.toString()] = loc3;
            }
            if (loc1[this._map["pickDrugIdx"]] != null) 
            {
                this.pickDrugIdx = loc1[this._map["pickDrugIdx"]];
                this.setItemTypeArr(this.pickDrugIdx, this.pickDrug);
            }
            if (loc1[this._map["pickOtherThingsIdx"]] != null) 
            {
                this.pickOtherThingsIdx = loc1[this._map["pickOtherThingsIdx"]];
                this.setItemTypeArr(this.pickOtherThingsIdx, this.pickOtherThings);
            }
            if (loc1[this._map["skillObj"]] != null) 
            {
                this.skillObj = loc1[this._map["skillObj"]];
            }
            if (loc1[this._map["skillShowObj"]] != null) 
            {
                this.skillShowObj = loc1[this._map["skillShowObj"]];
            }
            return loc1;
        }

        /* internal  */reInitSkill(arg1: Object): Array<any>
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc7=0;
            if (arg1[this._map["skillsArr"]] == null) 
            {
                return null;
            }
            var loc6=arg1[this._map["skillsArr"]];
            loc1 = 0;
            while (loc1 < loc6.length) 
            {
                loc7 = (loc6[loc1] as Array<any>).length;
                loc3 = loc6[loc1] as Array<any>;
                if (loc7 > 10) 
                {
                    loc3 = (loc6[loc1] as Array<any>).splice(10);
                }
                loc2 = 0;
                while (loc2 < 10) 
                {
                    if (loc2 >= loc7) 
                    {
                        loc3.push(0);
                    }
                    if (loc3[loc2] != 0) 
                    {
                        loc4 = SkillRules.getPostionById(loc3[loc2]);
                        if ((loc5 = Cache.instance.skill.getSkillByPos(loc4, loc3[loc2])) != null) 
                        {
                            loc3[loc2] = loc5.skillId;
                        }
                    }
                    ++loc2;
                }
                ++loc1;
            }
            return loc6;
        }

        /* internal  */reInitSkillShow(arg1: Object, arg2: Array<any>): Array<any>
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc7=null;
            if (arg1[this._map["skillShowArr"]] == null) 
            {
                return null;
            }
            var loc6=arg1[this._map["skillShowArr"]];
            loc1 = 0;
            while (loc1 < loc6.length) 
            {
                if ((loc7 = loc6[loc1]).length > 10) 
                {
                    loc7 = loc7.splice(10);
                }
                if (arg2 != null) 
                {
                    loc3 = arg2[loc1];
                    loc2 = 0;
                    while (loc2 < loc7.length) 
                    {
                        if (loc7[loc2] != 0) 
                        {
                            loc4 = SkillRules.getPostionById(loc7[loc2]);
                            if (loc5 = Cache.instance.skill.getSkillByPos(loc4, loc7[loc2])) 
                            {
                                loc7[loc2] = loc5.skillId;
                            }
                        }
                        if (loc7[loc2] == 0 && loc3 && !(loc3[loc2] == 0)) 
                        {
                            loc7[loc2] = loc3[loc2];
                        }
                        ++loc2;
                    }
                }
                ++loc1;
            }
            return loc6;
        }

        /* internal  */setItemTypeArr(arg1: Array<any>, arg2: Array<any>): void
        {
            var loc1=null;
            arg2.splice(0);
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                loc1 = ItemTypeManager.instance.getItemType(arg1[loc2]);
                arg2.push(loc1);
                ++loc2;
            }
            return;
        }

        public copy(arg1: AutoFightInfo): void
        {
            this.attackMonster = arg1.attackMonster;
            this.acceptTeam = arg1.acceptTeam;
            this.pickThing = arg1.pickThing;
            this.fSkill = arg1.fSkill;
            this.pSkill = arg1.pSkill;
            this.locRevive = arg1.locRevive;
            this.backCity = arg1.backCity;
            this.callPet = arg1.callPet;
            this.pickEquip = arg1.pickEquip;
            this.careerEquip = arg1.careerEquip;
            this.pickThings = arg1.pickThings;
            this.petEatDrug = arg1.petEatDrug;
            this.skillIdx = arg1.skillIdx;
            if (arg1.monsterArr) 
            {
                this.monsterArr = arg1.monsterArr.concat();
            }
            if (arg1.skillOther) 
            {
                this.skillOther = arg1.skillOther.concat();
            }
            if (arg1.pickDrugIdx) 
            {
                this.pickDrugIdx = arg1.pickDrugIdx.concat();
                this.setItemTypeArr(this.pickDrugIdx, this.pickDrug);
            }
            if (arg1.pickOtherThingsIdx) 
            {
                this.pickOtherThingsIdx = arg1.pickOtherThingsIdx.concat();
                this.setItemTypeArr(this.pickOtherThingsIdx, this.pickOtherThings);
            }
            if (arg1.skillObj != null) 
            {
                if (this.skillObj == null) 
                {
                    this.skillObj = {};
                }
                this.copySkillObject(arg1.skillObj, this.skillObj);
            }
            if (arg1.skillShowObj != null) 
            {
                if (this.skillShowObj == null) 
                {
                    this.skillShowObj = {};
                }
                this.copySkillObject(arg1.skillShowObj, this.skillShowObj);
            }
            return;
        }

        /* internal  */copySkillObject(arg1: Object, arg2: Object): void
        {
            var loc1=undefined;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=arg1;
            for (loc1 in loc5) 
            {
                loc2 = arg1[loc1] as Array<any>;
                if (arg2[loc1] == null) 
                {
                    arg2[loc1] = this.getDefaultArrValue();
                }
                loc3 = arg2[loc1] as Array<any>;
                this.copyArray(loc2, loc3);
            }
            return;
        }

        /* internal  */copyArray(arg1: Array<any>, arg2: Array<any>): void
        {
            var loc1=0;
            var loc2=0;
            if (arg1 == null || arg2 == null) 
            {
                return;
            }
            var loc3=[];
            loc1 = 0;
            while (loc1 < arg1.length) 
            {
                loc3 = arg1[loc1];
                if (!(arg2[loc1] == null) && !(loc3 == null)) 
                {
                    loc2 = 0;
                    while (loc2 < loc3.length) 
                    {
                        arg2[loc1][loc2] = loc3[loc2];
                        ++loc2;
                    }
                }
                ++loc1;
            }
            return;
        }

        public setAutoFightInfo(arg1: string, arg2: Boolean): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case "autoAttackMonster":
                {
                    this.attackMonster = arg2;
                    break;
                }
                case "autoPickSomething":
                {
                    this.pickThing = arg2;
                    break;
                }
                case "autoAcceptTeam":
                {
                    this.acceptTeam = arg2;
                    break;
                }
                case "skillForFriend":
                {
                    this.fSkill = arg2;
                    break;
                }
                case "skillForPet":
                {
                    this.pSkill = arg2;
                    break;
                }
                case "autoCallPet":
                {
                    this.callPet = arg2;
                    break;
                }
                case "autoBackCity":
                {
                    this.backCity = arg2;
                    break;
                }
                case "localeRevive":
                {
                    this.locRevive = arg2;
                    break;
                }
                case "autoCollectMonster":
                {
                    this.autoCollect = arg2;
                    break;
                }
                case "petEatDrug":
                {
                    this.petEatDrug = arg2;
                    break;
                }
            }
            return;
        }

        public get skillArrPlan(): Array<any>
        {
            if (this.skillIdx == -1) 
            {
                return [];
            }
            var loc1=this.getSkillArr();
            if (loc1 == null || loc1.length == 0) 
            {
                return [];
            }
            if (this.skillIdx >= loc1.length) 
            {
                this.skillIdx = 0;
            }
            return loc1[this.skillIdx];
        }

        public clearAutoFightSkill(): void
        {
            this.skillObj[Cache.instance.role.careerEnabled.toString()] = this.getDefaultArrValue();
            this.skillShowObj[Cache.instance.role.careerEnabled.toString()] = this.getDefaultArrValue();
            return;
        }

        public getSkillArr(): Array<any>
        {
            if (this.skillObj[Cache.instance.role.careerEnabled.toString()] == null || this.skillObj[Cache.instance.role.careerEnabled.toString()].length == 0) 
            {
                this.skillObj[Cache.instance.role.careerEnabled.toString()] = this.getDefaultArrValue();
            }
            return this.skillObj[Cache.instance.role.careerEnabled.toString()] as Array<any>;
        }

        public setSkillShowArr(arg1, arg2: int): void
        {
            if (arg1 == null || arg2 < 0) 
            {
                return;
            }
            var loc1=Cache.instance.role.careerEnabled;
            if (this.skillShowObj == null) 
            {
                this.skillShowObj = {};
            }
            if (this.skillShowObj[loc1.toString()] == null) 
            {
                this.skillShowObj[loc1.toString()] = this.getDefaultArrValue();
            }
            this.skillShowObj[loc1.toString()][arg2] = arg1;
            return;
        }

        public getSkillShowArr(): Array<any>
        {
            if (this.skillShowObj[Cache.instance.role.careerEnabled.toString()] == null || this.skillShowObj[Cache.instance.role.careerEnabled.toString()].length == 0) 
            {
                this.skillShowObj[Cache.instance.role.careerEnabled.toString()] = this.getDefaultArrValue();
            }
            return this.skillShowObj[Cache.instance.role.careerEnabled.toString()] as Array<any>;
        }

        /* internal  */getDefaultArrValue(): Array<any>
        {
            return [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
        }

        public clearToBaseAndSecond(): void
        {
            var loc1={};
            var loc2={};
            var loc3=Cache.instance.role.careerBasic.toString();
            var loc4=Cache.instance.role.careerSecond.toString();
            loc1[loc3] = this.skillShowObj[loc3];
            loc1[loc4] = this.getDefaultArrValue();
            loc2[loc3] = loc2[loc3];
            loc2[loc4] = this.getDefaultArrValue();
            this.skillShowObj = loc1;
            this.skillObj = loc2;
            return;
        }

        public /* var */skillOther: Array<any>;

        public /* var */autoCollect: Boolean=true;

        public /* var */skillIdx: int=0;

        public /* var */skillObj: Object;

        public /* var */attackMonster: Boolean=true;

        public /* var */pickDrug: Array<any>;

        public /* var */pickDrugIdx: Array<any>;

        public /* var */pickOtherThings: Array<any>;

        public /* var */pickOtherThingsIdx: Array<any>;

        public /* var */skillShowObj: Object;

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        public /* var */alter: Boolean=false;

        public /* var */isBrief: Boolean=true;

        public /* var */isAutoFight: Boolean=false;

        public /* var */pickThing: Boolean=true;

        public /* var */acceptTeam: Boolean=false;

        public /* var */fSkill: Boolean=false;

        public /* var */pSkill: Boolean=false;

        public /* var */callPet: Boolean=true;

        public /* var */backCity: Boolean=false;

        public /* var */monsterArr: Array<any>;

        public /* var */locRevive: Boolean=false;

        public /* var */petEatDrug: Boolean=true;

        public /* var */pickEquip: int=0;

        public /* var */careerEquip: int=0;

        public /* var */pickThings: int=0;
    }
